package d01007;

public class Person {
    private String name;
    private int age;
    private String gender;
    private Person partner;
    public Person(String name,int age,String gender){
        this.name=name;
        this.age=age;
        this.gender=gender;
        this.partner=null;
    }

    public String marry(Person p){
        //1.结婚对象不能为空
        if(null==p){
           return "你没有结婚对象....";
        }
        //2.判断同性
        if(this.gender.equals(p.gender)){
            return "你俩同性,不能结婚.....";
        }
        //3.判断年龄
        if("男".equals(this.gender)&&this.age<22 || "女".equals(this.gender)&&this.age<20){
            return "你未达到法定结婚年龄，允许结婚....";
        }

        if("男".equals(p.gender)&&p.age<22 || "女".equals(p.gender)&&p.age<20){
            return "你未达到法定结婚年龄，允许结婚....";
        }
        //判断是否已婚
        if(null!=this.partner){
            return "你将犯重婚罪......";
        }
        if(null!=p.partner){
            return "ta已婚......";
        }
        //结婚成功
        this.partner=p;
        p.partner=this;
        return "恭喜百年好合......";
    }
    //离婚方法
    public String divoce(Person p){
        if(this.partner==p&&p.partner==this){
            this.partner=null;
            p.partner=null;
            return "好聚好散....";
        }
        return "不存在婚姻关系,无法离婚......";
    }
}
